home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / ICMPDUMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-29  |  1.9 KB  |  76 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "internet.h"
  4. #include "netuser.h"
  5. #include "icmp.h"
  6. #include "trace.h"
  7.  
  8. #if !defined(_lint)
  9. static char rcsid[] OPTIONAL = "$Id: icmpdump.c,v 1.10 1996/08/29 12:11:16 root Exp root $";
  10. #endif
  11.  
  12.  
  13. /* Dump an ICMP header */
  14. void
  15. icmp_dump (fp, bpp, source, dest, check)
  16. FILE *fp;
  17. struct mbuf **bpp;
  18. uint32 source OPTIONAL,dest OPTIONAL;
  19. int check;        /* If 0, bypass checksum verify */
  20. {
  21. struct icmp icmp;
  22. int16 csum;
  23.  
  24.     if (bpp == NULLBUFP || *bpp == NULLBUF)
  25.         return;
  26.  
  27.     csum = cksum (NULLHEADER, *bpp, len_p (*bpp));
  28.     (void) ntohicmp (&icmp, bpp);
  29.     
  30.     traceprintf (fp, "ICMP: type %s", smsg(Icmptypes, ICMP_TYPES, uchar(icmp.type)));
  31.  
  32.     switch (uchar(icmp.type))    {
  33.         case ICMP_DEST_UNREACH:
  34.             traceprintf (fp, " code %s", smsg (Unreach, NUNREACH, uchar(icmp.code)));
  35.             break;
  36.         case ICMP_REDIRECT:
  37.             traceprintf (fp, " code %s", smsg (Redirect, NREDIRECT, uchar(icmp.code)));
  38.             traceprintf (fp, " new gateway %s", inet_ntoa (icmp.args.address));
  39.             break;
  40.         case ICMP_TIME_EXCEED:
  41.             traceprintf (fp, " code %s", smsg (Exceed, NEXCEED, uchar(icmp.code)));
  42.             break;
  43.         case ICMP_PARAM_PROB:
  44.             traceprintf (fp, " pointer %u", icmp.args.pointer);
  45.             break;
  46.         case ICMP_ECHO:
  47.         case ICMP_ECHO_REPLY:
  48.         case ICMP_INFO_RQST:
  49.         case ICMP_INFO_REPLY:
  50.         case ICMP_TIMESTAMP:
  51.         case ICMP_TIME_REPLY:
  52.             traceprintf (fp, " id %u seq %u", icmp.args.echo.id, icmp.args.echo.seq);
  53.             break;
  54.         default:
  55.             break;
  56.     }
  57.     if (check && csum != 0)
  58.         traceprintf (fp, " CHECKSUM ERROR (%u)", csum);
  59.  
  60.     traceprintf (fp, "\n");
  61.     /* Dump the offending IP header, if any */
  62.     switch (icmp.type)    {
  63.         case ICMP_DEST_UNREACH:
  64.         case ICMP_TIME_EXCEED:
  65.         case ICMP_PARAM_PROB:
  66.         case ICMP_QUENCH:
  67.         case ICMP_REDIRECT:
  68.             traceprintf (fp, "Returned ");
  69.             ip_dump (fp, bpp, 0);
  70.             break;
  71.         default:
  72.             break;
  73.     }
  74. }
  75.  
  76.